package main

import (
	"encoding/json"
	"os"
)

func SaveConfig() map[string]interface{} {
	dataMap := make(map[string]interface{})
	jsonData, err := json.Marshal(MapJson)
	if err != nil {
		dataMap["code"] = 500
		dataMap["msg"] = err.Error()
	}
	jsonString := string(jsonData)
	// 将 JSON 字符串写入文件
	file, err := os.Create("dataList.json")
	if err != nil {
		dataMap["code"] = 500
		dataMap["msg"] = err.Error()
	}
	_, err = file.WriteString(jsonString)
	if err != nil {
		dataMap["code"] = 500
		dataMap["msg"] = err.Error()
	}
	file.Close()
	return dataMap
}
func SaveFile(str, fileName string) map[string]interface{} {
	dataMap := make(map[string]interface{})
	file, err := os.Create(fileName)
	if err != nil {
		dataMap["code"] = 500
		dataMap["msg"] = err.Error()
	}
	_, err = file.WriteString(str)
	if err != nil {
		dataMap["code"] = 500
		dataMap["msg"] = err.Error()
	}
	file.Close()
	return dataMap
}
